package com.linchong.concurrency.aqs;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author linchong
 * @version 1.0
 * @Date: 2020-12-09 11:29
 * @Description: FutureExample$
 */
@Slf4j
public class FutureExample {

	static class MyCallable implements Callable<String> {

		/**
		 * Computes a result, or throws an exception if unable to do so.
		 *
		 * @return computed result
		 * @throws Exception if unable to compute a result
		 */
		@Override
		public String call() throws Exception {
			log.info("do something in callable");
			Thread.sleep(4_000);
			return "Done";
		}
	}

	public static void main(String[] args) throws Exception {
		ExecutorService executorService = Executors.newCachedThreadPool();
		Future<String> future = executorService.submit(new MyCallable());
		log.info("do something in main");
		Thread.sleep(1_000);
		String result = future.get();
		log.info("result:{}",result);
		executorService.shutdown();

	}
}














